package com.hclc.util.date;

import lombok.Data;

import java.time.LocalDateTime;

/**
 * @描述
 * @参数注释：
 * @创建人 ws
 * @郵箱 zhisirudan@gmail.com
 * @创建时间 2019/10/31
 */
@Data
public class CronUtil {
    public static String getCron(
            int year,
            int month,
            int day,
            int hour,
            int minute,
            int second
    ){
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append(second + " ")
                     .append(minute + " ")
                     .append(hour + " ")
                     .append(day + " ")
                     .append(month + " ")
                     .append("? ")
                     .append(year);
        return stringBuilder.toString();
    }
    public static String  getCron(
            LocalDateTime localDateTime
    ){
        int year = localDateTime.getYear();
        int month = localDateTime.getMonthValue();
        int day = localDateTime.getDayOfMonth();
        int hour = localDateTime.getHour();
        int minute = localDateTime.getMinute();
        int second = localDateTime.getSecond();
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append(second + " ")
                .append(minute + " ")
                .append(hour + " ")
                .append(day + " ")
                .append(month + " ")
                .append("? ")
                .append(year);
        return stringBuilder.toString();
    }


    public static void main(String[] args) {
        LocalDateTime now = LocalDateTime.now();
        LocalDateTime cron = now.minusHours(-2).minusMinutes(-1);
        String cronExpress = getCron(cron);
        System.out.println(now);
        System.out.println(cron);
        System.out.println(cronExpress);
    }
}
